Page({
  data: {
    medicines: [
      { id: 1, name: '狗狗维生素', price: 50 },
      { id: 2, name: '猫咪营养膏', price: 80 },
      { id: 3, name: '宠物驱虫药', price: 120 },
    ],
    cart: []
  },
  addToCart(e) {
    const { id } = e.currentTarget.dataset;
    const medicine = this.data.medicines.find(m => m.id === id);
    this.setData({
      cart: [...this.data.cart, medicine]
    });
    wx.showToast({
      title: '已加入购物车',
      icon: 'success',
      duration: 2000
    });
  },
  checkout() {
    console.log('结算', this.data.cart);
    // 这里添加结算逻辑
    wx.showToast({
      title: '结算成功',
      icon: 'success',
      duration: 2000
    });
    this.setData({ cart: [] });
  }
})
